<?php

class Rapide_User implements Rapide_User_Interface
{
	private
		$_oSession,
		$_oDataSession;

	public function __construct()
	{
		$this->_oSession		 = new Rapide_Session('Rapide_User');
		$this->_oDataSession = new Rapide_Session('Rapide_User_Data');

		$this->_oSession->start();
		$this->_oDataSession->start();

		if(!isset($this->_oSession->authenticated))
			$this->_oSession->authenticated = false;

	 if(!isset($this->_oSession->role))
		 $this->_oSession->role = array('root' => false, 'name' => '');
		
	 if(!isset($this->_oSession->rules))
		 $this->_oSession->rules = array();
	}

	public function setRole($bRoot = false, $sName = '') {
	 $this->_oSession->role = array('root' => $bRoot, 'name' => $sName);
	}

	public function getRole() {
		return $this->_oSession->role;
	}

	public function setAccessRules(array $aRules = array()) {
		$this->_oSession->rules = $aRules;
	}

	public function getAccessRules() {
		return $this->_oSession->rules;
	}

	public function isAuthenticated()
	{
		return $this->_oSession->authenticated;
	}

	public function setAuthenticated($bAuthenticated = true)
	{
		$this->_oSession->authenticated = (bool)$bAuthenticated;
	}

	public function __get($sParameter)
	{
		return $this->_oDataSession->$sParameter;
	}

	public function __set($sParameter, $mValue)
	{
		$this->_oDataSession->$sParameter = $mValue;
	}

	public function __isset($sParameter)
	{
		return isset($this->_oDataSession->$sParameter);
	}

	public function destroy()
	{
		$this->setRole(false, '');
		$this->setAccessRules(array());
		$this->setAuthenticated(false);

		$this->_oSession->close();
		$this->_oDataSession->close();
	}
}

?>